public class MySingleList{

    static class ListNone {
        public int val;
        public ListNone next;


        public ListNone(int val) {
            this.val = val;
        }

        public int getVal() {
            return val;
        }
    }

    public ListNone head;     //表示当前列表的头节点

    public int listSize;

    public ListNone detectCycle(ListNone head) {
        ListNone fast = head;
        ListNone slow = head;
        while(fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
            if(fast == slow) {
                break;
            }
        }
        if(fast == null && fast.next == null) {
            return null;   //没有环，没有入口点
        }
        fast = head;
        while(fast != slow) {
            fast = fast.next;
            slow = slow.next;
        }
        return fast;
    }

}